package com.icinfo.cloud.provider.punish.common.publicsecurityentrust.controller;


import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.dto.*;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.service.ICasePublicSecurityEntrustDocumentNumberService;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.vo.PublicSecurityDocumentNumberDetailsVo;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.vo.PublicSecurityDocumentNumberVO;
import com.icinfo.framework.common.web.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 公安委托文号相关配置信息控制层
 *
 * @author HKxxx
 * @date 2024/1/2 10:59
 */
@RestController
@RefreshScope
@RequestMapping("/punish/common/publicSecurityEntrustDocumentNumber")
@Slf4j
public class CasePublicSecurityEntrustDocumentNumberController {

    @Resource
    private ICasePublicSecurityEntrustDocumentNumberService casePublicSecurityEntrustDocumentNumberService;


    /**
     * 保存公安委托文号配置
     *
     * @param reqDTO
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存公安委托文号配置", httpMethod = "POST")
    public Result<String> save(@RequestBody @Validated PublicSecurityDocumentNumberReqDTO reqDTO) {
        return Result.success(Constant.STRING_SAVE_SUCCESS, casePublicSecurityEntrustDocumentNumberService.save(reqDTO));
    }

    /**
     * 根据当前登录用户查询当前的执法编码
     * @return
     */
    @GetMapping("/getEnforcementCodeByCurrentUser")
    @ApiOperation(value = "根据当前登录用户查询当前的执法编码", httpMethod = "GET")
    public Result<String> getEnforcementCodeByCurrentUser() {
        return Result.success(Constant.STRING_GET_SUCCESS, casePublicSecurityEntrustDocumentNumberService.getEnforcementCodeByCurrentUser());
    }


    /**
     * 校验主号段是否是插入号段或存在号段交集
     *
     * @param reqDTO
     * @return
     */
    @PostMapping("/verifyMainDocumentNumber")
    @ApiOperation(value = "校验公安文号", httpMethod = "POST")
    public Result<String> verifyMainDocumentNumber(@RequestBody @Validated PublicSecurityDocumentNumberVerifyDTO reqDTO) {
        casePublicSecurityEntrustDocumentNumberService.verifyMainDocumentNumber(reqDTO);
        return Result.success(Constant.STRING_SUCCESS_CH);
    }

    /**
     * 根据文号配置id删除文号配置数据
     *
     * @param deleteDTO
     * @return
     */
    @PostMapping("/deleteById")
    @ApiOperation(value = "删除公安委托文号配置", httpMethod = "POST")
    public Result<String> deleteById(@RequestBody @Validated PublicSecurityDocumentNumberDeleteDTO deleteDTO) {
        casePublicSecurityEntrustDocumentNumberService.deleteById(deleteDTO.getId());
        return Result.success(Constant.STRING_OPERATE_SUCCESS);
    }

    @PostMapping("/pageList")
    @ApiOperation(value = "查询公安委托文号配置", httpMethod = "POST")
    public Result<PageResponse<PublicSecurityDocumentNumberVO>> pageList(@RequestBody @Validated PublicSecurityDocumentNumberPageDTO queryDTO) {
        return Result.success(Constant.STRING_GET_SUCCESS, casePublicSecurityEntrustDocumentNumberService.pageList(queryDTO));
    }

    @GetMapping("/getPublicSecurityDocumentNumber")
    @ApiOperation(value = "获取文号", httpMethod = "GET")
    public Result<String> getPublicSecurityDocumentNumber(@RequestParam String orgCode) {
        return Result.success(Constant.STRING_GET_SUCCESS, casePublicSecurityEntrustDocumentNumberService.getPublicSecurityDocumentNumber(orgCode));
    }

    @GetMapping("/hasSurplusNumber")
    @ApiOperation(value = "是否存在余号", httpMethod = "GET")
    public Result<Boolean> hasSurplusNumber(@RequestParam String orgCode) {
        return Result.success(Constant.STRING_GET_SUCCESS, casePublicSecurityEntrustDocumentNumberService.hasRemainNumber(orgCode));
    }

    @PostMapping("/publicSecurityRollbackDocumentNumber")
    @ApiOperation(value = "回滚公安委托文号", httpMethod = "POST")
    public Result publicSecurityRollbackDocumentNumber(@RequestBody @Validated PublicSecurityDocumentNumberRollbackDTO queryDTO) {
        casePublicSecurityEntrustDocumentNumberService.publicSecurityRollbackDocumentNumber(queryDTO);
        return Result.success(Constant.STRING_OPERATE_SUCCESS);
    }

    @PostMapping("/residualNumberWarning")
    @ApiOperation(value = "剩余文号警告", httpMethod = "POST")
    public Result residualNumberWarning(@RequestBody @Validated PublicSecurityDocumentNumberRollbackDTO queryDTO) {
        casePublicSecurityEntrustDocumentNumberService.residualNumberWarning(queryDTO);
        return Result.success(Constant.STRING_SEND_SUCCESS);
    }

    @GetMapping("/details")
    @ApiOperation(value = "公安委托文号详情查询", httpMethod = "GET")
    public Result<PublicSecurityDocumentNumberDetailsVo> details(String id) {
        return Result.success(Constant.INTEGER_200, casePublicSecurityEntrustDocumentNumberService.details(id));
    }

}
